//单例模式  懒汉模式
//线程不安全  所以要加锁  并且需要双判断
class SingletonLazy {
    private static volatile SingletonLazy instance = null;

    private static Object locker = new Object();

    public static SingletonLazy getInstance() {
        if(instance == null) {
            synchronized(locker) {
                if (instance == null) {
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }

    private SingletonLazy() {
    }
    ;

}

public class Demo28 {
    public static void main(String[] args) throws InterruptedException {
        SingletonLazy s1 = SingletonLazy.getInstance();
        SingletonLazy s2 = SingletonLazy.getInstance();
        System.out.println(s1 == s2);
    }

}
